home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABSlide.c
-
- NAME
- ABSlide.c, part of the ABox project source code,
- responsible for handling the AboutBox slide class stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 9 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 26-apr-95 - ty - 1.0.7--fixed handling of return type from
- res->Event() within ForEach()
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
-
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABSlide.h"
- #include "ABResource.h"
-
- #include "ABPict.h"
- #include "ABText.h"
- #include "ABStr.h"
- #include "ABSound.h"
-
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
-
- /*=============================== ABSlide::ABSlide ================================*/
- ABSlide::ABSlide(void)
- {
- this->Resources() = new ABLinkedList;
- this->SlideNumber() = 0;
- this->Initialized() = false;
- } // end ABSlide
-
-
-
- /*=============================== ABSlide::~ABSlide ================================*/
- ABSlide::~ABSlide(void)
- {
- this->ResetResources();
-
- } // end ~ABSlide
-
-
-
- /*=============================== ABSlide::ResetResources ================================*/
- void
- ABSlide::ResetResources(void)
- {
- if (this->HasResources())
- {
- delete this->Resources();
- this->Resources() = NULL;
- }
- } // end ResetResources
-
-
-
- /*=============================== ABSlide::GetProperty ================================*/
- OSErr ABSlide::GetProperty(ABProperty prop,
- void *ptr,
- long *ptrSize)
- {
- OSErr error = noErr;
- long pSize;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABSlideNumber:
- (*(short *)ptr) = this->GetSlideNumber();
- pSize = kABSlideNumberSize;
- break;
- case kABSlideIndex:
- (*(ABIndex *)ptr) = this->Ordinal();
- pSize = kABSlideIndexSize;
- break;
- case kABSlideNumberOfElements:
- if (this->HasResources())
- (*(ABListCount *)ptr) = this->Resources()->Count();
- else
- (*(ABListCount *)ptr) = 0;
- pSize = kABSlideNumberOfElementsSize;
- default:
- error = kABSlideSuperProperties::GetProperty(prop, ptr, ptrSize);
- break;
- } // end switch block
-
- if (ptrSize && !error)
- *ptrSize = pSize;
- return error;
-
- } // end GetProperty
-
-
-
- /*=============================== ABSlide::SetProperty ================================*/
- OSErr ABSlide::SetProperty(ABProperty prop,
- void *ptr,
- long ptrSize)
- {
- OSErr error = noErr;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABSlideNumber:
- this->SlideNumber() = (*(short *)ptr);
- break;
- case kABSlideNumberOfElements:
- error = kABPropertyReadOnly;
- break;
- default:
- error = kABSlideSuperProperties::SetProperty(prop, ptr, ptrSize);
- break;
- } // end switch block
-
- return error;
-
- } // end SetProperty
-
-
-
-
-
- /*=============================== ABSlide::InitializeObject ================================*/
- OSErr ABSlide::InitializeObject(void)
- {
- OSErr error = noErr;
-
- ABResource *res;
- short resID = this->GetSlideNumber();
-
- // begin here...
- //
- // attempt to load each of the resources we'd
- // be interested in for the slide. The caller may
- // have already added some to our list, so we'll
- // concern ourselves with appending to the list.
- //
- if (this->IsInitialized())
- return noErr;
-
- res = new ABPict;
- if (res)
- {
- error = res->SetProperty (kABResourceResID, &resID, kABResourceResIDSize);
- if (res->CheckFile(NULL))
- {
- error = this->AddResource(res);
- } else {
- delete res;
- } // end if block
- } // end if block
-
-
- res = new ABText;
- if (res)
- {
- error = res->SetProperty (kABResourceResID, &resID, kABResourceResIDSize);
- if (res->CheckFile(NULL))
- {
- error = this->AddResource(res);
- } else {
- delete res;
- } // end if block
- } // end if block
-
-
- res = new ABSound;
- if (res)
- {
- error = res->SetProperty (kABResourceResID, &resID, kABResourceResIDSize);
- if (res->CheckFile(NULL))
- {
- error = this->AddResource(res);
- } else {
- delete res;
- } // end if block
- } // end if block
-
-
- res = new ABStr;
- if (res)
- {
- error = res->SetProperty (kABResourceResID, &resID, kABResourceResIDSize);
- if (res->CheckFile(NULL))
- {
- error = this->AddResource(res);
- } else {
- delete res;
- } // end if block
- } // end if block
-
- this->Initialized() = true;
-
- return error;
-
- } // end InitializeObject
-
-
-
-
- /*=============================== ABSlide::ForEach ================================*/
- //
- // ForEach is an internal method to do some action/method for each
- // list member.
- //
- OSErr ABSlide::ForEach (ABMessage message, void *data)
- {
- OSErr error = noErr;
- long i;
- long limit;
- ABResource *res = NULL;
-
- // begin here...
-
- if (this->IsntInitialized() && (message != kABMessageStop))
- error = this->InitializeObject();
-
- if (this->HasResources() && !error)
- limit = this->Resources()->Count();
- else
- return error;
-
- if (limit < 1)
- {
- error = noErr;
- } else {
- for (i = 1; i <= limit; ++i)
- {
- Boolean handled = false;
-
- res = (ABResource *)(this->Resources()->NthLink(i));
- if (res)
- {
- switch (message)
- {
- case kABMessageDraw:
- error = res->Draw((WindowPtr)data);
- break;
- case kABMessageUpdate:
- error = res->Update((WindowPtr)data);
- break;
- case kABMessageEvent:
- handled = res->Event((EventRecord *)data);
- break;
- case kABMessageStop:
- error = res->Stop();
- break;
- } // end switch block
- } else {
- // couldn't locate the ith resource for this slide! yikes!
- //
- res = NULL;
- } // end if block
- } // end for loop
-
- }
- return error;
-
- } // end ForEach()
-
-
-
-
- /*=============================== ABSlide::Draw ================================*/
- OSErr ABSlide::Draw(WindowPtr window)
- {
- return this->ForEach (kABMessageDraw, window);
- } // end Draw
-
-
-
-
-
- /*=============================== ABSlide::AddResource ================================*/
- OSErr ABSlide::AddResource(ABResource *obj)
- {
- OSErr error = noErr;
- short resID = this->GetSlideNumber();
-
- // begin here...
- //
- // the intent here is to add the given object to the
- // list maintained by the slide. The object will be
- // given the same resource ID# as the slide.
- //
- if (obj && this->HasResources())
- {
- error = obj->SetProperty (kABResourceResID, &resID, kABSlideNumberSize);
- this->Resources()->Append ((ABLink *)obj);
- } else {
- error = paramErr;
- } // end if block
-
- return error;
-
- } // end AddResource
-
-
-
-
-
- /*=============================== ABSlide::DropResource ================================*/
- OSErr ABSlide::DropResource(ABResource *obj)
- {
- OSErr error = noErr;
-
- // begin here...
- //
- // the intent here is to delete the given object to the
- // list maintained by the slide.
- //
- if (obj && this->HasResources())
- {
- this->Resources()->Detach ((ABLink *)(obj));
- } else {
- error = paramErr;
- } // end if else block
-
- return error;
-
- } // end DropResource
-
-
-
-
-
- /*=============================== ABSlide::Update ================================*/
- OSErr ABSlide::Update(WindowPtr window)
- {
- return this->ForEach (kABMessageUpdate, window);
- } // end Update
-
-
-
-
- /*=============================== ABSlide::Event ================================*/
- Boolean ABSlide::Event(EventRecord *eventRec)
- {
- return (Boolean)this->ForEach (kABMessageEvent, eventRec);
-
- } // end Event
-
-
-
- /*=============================== ABSlide::Stop ================================*/
- OSErr ABSlide::Stop(void)
- {
- return this->ForEach (kABMessageStop, NULL);
- } // end Stop
-
-
-
-
- /*=============================== ABSlide::GetResourceOfType ================================*/
- ABResource *ABSlide::GetResourceOfType(ResType type)
- {
- ABResource *rsrc;
- ABIndex i;
- ABListCount limit;
- ResType resType;
- long size = kABResourceResTypeSize;
- OSErr error = noErr;
-
- // begin here...
- if (this->IsntInitialized())
- error = this->InitializeObject();
-
-
- if (this->HasResources())
- limit = this->Resources()->Count();
- else
- return NULL;
-
- for (i = 1; i <= limit; ++i)
- {
- rsrc = (ABResource *)(this->Resources()->NthLink(i));
- if (!rsrc)
- continue;
- error = rsrc->GetProperty(kABResourceResType, &resType, &size);
- if (!error && (resType == type))
- return rsrc;
- } // end for loop
-
- return NULL;
-
- } // end GetResourceOfType
-
-
-
-
-
-
- /*=============================== ABSlide::Resize ===============================*/
- //
- // this function will rearrange and resize the picture and the
- // text fields that appear on a slide.
- //
- // 10-nov-93 - ty - d25 changes to improve picture
- // placement
- //
- // 20-nov-93 - ty - d26 changes to support the unification
- // of the slideField with the slideTitleField
- // to reduce the number of things on the screen
- // and to provide more room for slides if no
- // title's are present.
- //
- // is called by:
- //
- OSErr ABSlide::Resize (Rect const *field)
- {
- OSErr error = noErr;
-
- ABResource *pict;
- ABResource *text;
- ABResource *title;
-
- Rect area;
- Rect pictRect;
- Rect textRect;
- Rect titleRect;
-
- short fieldWidth,
- fieldHeight;
-
- short offsetX,
- offsetY;
-
- SlideElementPositions position = leftOrRight;
-
- PicHandle pictureH;
-
- short fontHeight; // 1.0a9p8 ty...added
- short maximumTitleHeight; // 1.0a9p8 ty...added
-
-
- // begin here...
-
- if (this->IsntInitialized())
- error = this->InitializeObject();
-
- if (this->DoesntHaveResources())
- return paramErr;
-
- if (!field)
- return paramErr;
- else
- area = *field;
-
- // erase the field...
- error = this->EraseFrame(area);
-
- // calculation of fontHeight and maximumTitleHeight for better box sizing
- fontHeight = ABUFonts::FindFontHeight();
- maximumTitleHeight = 2 * fontHeight;
-
- // get the slide elements we care about
- pict = this->GetResourceOfType(kABPictResource);
- text = this->GetResourceOfType(kABTextResource);
- title = this->GetResourceOfType(kABStringResource);
-
- // check to see if we should even bother
- if (!(pict || text || title))
- return error;
-
- titleRect = pictRect = textRect = area;
- if (title)
- {
- titleRect.top = titleRect.bottom - maximumTitleHeight;
- area.bottom = pictRect.bottom = textRect.bottom = titleRect.top - 2*kABdialogSpacing;
- } // end if block
-
- // now save the modified sub areas into the proper
- // slide elements
- if (pict)
- error = pict->SetProperty(kABObjectRect, &pictRect, kABObjectRectSize);
- if (text)
- error = text->SetProperty(kABObjectRect, &textRect, kABObjectRectSize);
- if (title)
- error = title->SetProperty(kABObjectRect, &titleRect, kABObjectRectSize);
-
- // now see if things need to be rearranged
- if (pict)
- {
- // now get the picture information
- error = pict->GetProperty(kABResourceHandle, &pictureH, NULL);
-
- if (pictureH && !error)
- {
- // 1.0a7 ty...the two following statements were rewritten to utilize (*pictureH)->picFrame
- // rather than the information from GetPictInfo.
- //
- ::HLock ((Handle)pictureH);
- pictRect.right = pictRect.left + ((*pictureH)->picFrame.right - (*pictureH)->picFrame.left);
- pictRect.bottom = pictRect.top + ((*pictureH)->picFrame.bottom - (*pictureH)->picFrame.top);
- ::HUnlock ((Handle)pictureH);
-
- // decide what the aspect ratio is and
- // where it should fit in the field.
- //
- if ((pictRect.right - pictRect.left) < (pictRect.bottom - pictRect.top))
- {
- position = leftOrRight;
- } else {
- position = aboveOrBelow;
- } // end if else block
-
- } else {
- // there is a problem with the handle,
- // so the picture element is basically useless to us.
- pict = NULL;
- pictRect.right = pictRect.top = pictRect.left = pictRect.bottom = 0;
- } // end if block
- } // end if (pict)
-
- // if the picture is smaller than our field then we'll just center
- // and display the picture; if the picture is larger than the field
- // we'll scale it.
- //
-
- fieldWidth = area.right - area.left;
- fieldHeight = area.bottom - area.top;
-
- // if there are both text and pict objects then we
- // need to arrange them properly on the field. If there
- // is only a pict, then it will be centered in the field.
- // If there is only a text, then it already has its field
- //
- if (text && pict)
- {
- if (position == aboveOrBelow)
- {
- //Rect box;
-
- // make enough room for the text area below...no additional
- // reduction is necessary
-
- //box = *field;
- //box.bottom -= kABscrollBarMinLength;
- //
- // addition of the scroll-bar area to the right
- // side to allow the pict to occupy the entire area
- // left to right, and move the bottom up to allow for
- // the minimum size text field possible.
- //
- area.right += kABscrollBarWidth;
- area.bottom -= kABscrollBarMinLength;
- error = this->ScaleRectToFit (pictRect, area, 1.0);
- // restore the field geometry
- area.bottom += kABscrollBarMinLength;
- area.right -= kABscrollBarWidth;
-
- // use the space below the picture as the text rect
- // and center the picture left/right
- //
- offsetX = (fieldWidth - (pictRect.right - pictRect.left))/2;
- offsetY = 0;
-
- } else {
- error = this->ScaleRectToFit (pictRect, area, kABreduceFactor);
- // use the space to the right of the picture as the textRect
- // and center the graphic top/bottom on the left.
- //
- offsetX = 0;
- offsetY = (fieldHeight - (pictRect.bottom - pictRect.top))/2;
-
- } // end if block
- } else if (pict && !text) {
- // addition of the scroll-bar area to the right
- // side to allow the pict to occupy the entire area,
- // both left to right and top to bottom
- //
- pictRect.right += kABscrollBarWidth;
- area.right += kABscrollBarWidth;
- error = this->ScaleRectToFit (pictRect, area, 1.0);
- area.right -= kABscrollBarWidth;
-
- // there is only a graphic, so we should center the graphic top/bottom
- // and left/right in the field.
- //
- offsetX = (fieldWidth - (pictRect.right - pictRect.left))/2;
- offsetY = (fieldHeight - (pictRect.bottom - pictRect.top))/2;
-
- } else if (text && !pict) {
- // there is only a text field, so let it occupy the whole field
- //
- offsetX = offsetY = 0;
-
- } // end if....elseif block
-
-
- // move the picture rect...
- //
- if (pict)
- ::OffsetRect (&pictRect, offsetX, offsetY);
-
- // and now size the text rect accordingly...
- if (text)
- {
- if (offsetX > 0)
- textRect.top = pictRect.bottom + kABdialogSpacing;
- if (offsetY > 0)
- textRect.left = pictRect.right + kABdialogSpacing;
- error = text->SetProperty(kABObjectRect, &textRect, kABObjectRectSize);
- } // end if block
-
- // now save the modified sub areas into the proper
- // slide elements
- if (pict)
- error = pict->SetProperty(kABObjectRect, &pictRect, kABObjectRectSize);
- if (title)
- error = title->SetProperty(kABObjectRect, &titleRect, kABObjectRectSize);
-
- // we're done!
- return error;
-
- } // end of function Resize()
-
-
-
- // end of file
-
-